using Publicuse.Appication;
using Publicuse.Autofac;
using Publicuse.Entity;
using Publicuse.Entity.AttributeUtil;
using Publicuse.Interface;
using Publicuse.Util;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace Publicuse.Application.system
{
    public class UserRoleApplication
    {
        private static BaesApplication baseApplication;
        private static UserRoleApplication userApplication;

        public static UserRoleApplication GetApplication(ServiceContainer container)
        {
            baseApplication = new BaesApplication(container);
            return userApplication;
        }

        static UserRoleApplication()
        {
            userApplication = new UserRoleApplication();
        }


        /// <summary>
        /// 使用指定用户角色备份信息
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="uId"></param>
        /// <param name="rids"></param>
        /// <param name="loginUserCode"></param>
        /// <returns></returns>
        public async Task<CommonResult> UserVersion(string uId, string rids, string loginUserCode)
        {
            return await Task.Factory.StartNew(()=> 
            {
                CommonResult result = new CommonResult();
                var table = TableAtributeUtil.GetTable<UserRole>();
                var sql = $"update {table} set rids=@rids where uId=@uId and status<>-9;";
                baseApplication.mySqlSugar.ExecuteSql(sql, new { rids = rids , uId = uId }, out var msg);
                result.msg =msg;
                return result;
            });
        }
    }
}
